/*
 * @lc app=leetcode.cn id=1758 lang=typescript
 *
 * [1758] 生成交替二进制字符串的最少操作数
 */

// @lc code=start
function minOperations(s: string): number {
    const n = new Array(s.length)
        .fill(0)
        .map((_, index) => (index % 2 ? 0 : 1))
        .join("");

    const m = new Array(s.length)
        .fill(0)
        .map((_, index) => (index % 2 ? 1 : 0))
        .join("");

    const countOne = (number: string) => {
        let count = 0;
        for (let i = 0; i < number.length; i++) {
            const element = number[i];
            if (element !== s[i]) count++;
        }
        return count;
    };

    return Math.min(countOne(n), countOne(m));
}
// @lc code=end
